/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * frameTabIndex.java
 *
 * Created on 19-may-2009, 16:14:17
 */

package gestiontipocampo;

import javax.swing.DefaultListModel;

/**
 *
 * @author Alberto
 */
public class frameTabIndex extends javax.swing.JFrame {

    /**
     * Creates new form frameTabIndex
     */
    public frameTabIndex( ) {
        initComponents();
        listModel = new DefaultListModel();
        jList1.setModel(listModel);
    }

    /**
     * Creates new form frameTabIndex
     */
    public frameTabIndex(frameFormulario parent, String [] valores) {
        initComponents();

        listModel = new DefaultListModel();
        listModel.removeAllElements();
        for(int i = 0; i < valores.length; ++i){
            listModel.addElement(valores[i]);
        }
        jList1.setModel(listModel);
        frameForm = parent;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jList1 = new javax.swing.JList();
        jLabel1 = new javax.swing.JLabel();
        botonSubir = new javax.swing.JButton();
        botonBajar = new javax.swing.JButton();
        botonAceptar = new javax.swing.JButton();
        botonCancelar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setName("Form"); // NOI18N
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        jList1.setName("jList1"); // NOI18N
        jScrollPane1.setViewportView(jList1);

        getContentPane().add(jScrollPane1, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 40, 170, 250));

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(gestiontipocampo.GestionTipoCampoApp.class).getContext().getResourceMap(frameTabIndex.class);
        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N
        getContentPane().add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 10, -1, -1));

        botonSubir.setText(resourceMap.getString("botonSubir.text")); // NOI18N
        botonSubir.setName("botonSubir"); // NOI18N
        botonSubir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonSubirActionPerformed(evt);
            }
        });
        getContentPane().add(botonSubir, new org.netbeans.lib.awtextra.AbsoluteConstraints(190, 90, -1, -1));

        botonBajar.setText(resourceMap.getString("botonBajar.text")); // NOI18N
        botonBajar.setName("botonBajar"); // NOI18N
        botonBajar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonBajarActionPerformed(evt);
            }
        });
        getContentPane().add(botonBajar, new org.netbeans.lib.awtextra.AbsoluteConstraints(190, 170, -1, -1));

        botonAceptar.setText(resourceMap.getString("botonAceptar.text")); // NOI18N
        botonAceptar.setName("botonAceptar"); // NOI18N
        botonAceptar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonAceptarActionPerformed(evt);
            }
        });
        getContentPane().add(botonAceptar, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 320, -1, -1));

        botonCancelar.setText(resourceMap.getString("botonCancelar.text")); // NOI18N
        botonCancelar.setName("botonCancelar"); // NOI18N
        botonCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonCancelarActionPerformed(evt);
            }
        });
        getContentPane().add(botonCancelar, new org.netbeans.lib.awtextra.AbsoluteConstraints(100, 320, -1, -1));

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void botonSubirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonSubirActionPerformed
        int index = jList1.getSelectedIndex();
        Object tmp = listModel.get(index);
        listModel.remove(index);
        listModel.add(index-1, tmp);
        jList1.setSelectedIndex(index-1);
    }//GEN-LAST:event_botonSubirActionPerformed

    private void botonBajarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonBajarActionPerformed
        int index = jList1.getSelectedIndex();
        Object tmp = listModel.get(index);
        listModel.remove(index);
        listModel.add(index+1, tmp);
        jList1.setSelectedIndex(index+1);
}//GEN-LAST:event_botonBajarActionPerformed

    private void botonCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonCancelarActionPerformed
        this.dispose();
}//GEN-LAST:event_botonCancelarActionPerformed

    private void botonAceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonAceptarActionPerformed
        //debe enviarse los datos de vuelta...
        int size = listModel.size();
        String[] valores = new String[size];
        for(int i = 0; i< size; ++i){
            valores[i] = (String)listModel.getElementAt(i);
        }
        frameForm.cambioTabIndex(valores);
        this.dispose();
}//GEN-LAST:event_botonAceptarActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {                
                new frameTabIndex().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton botonAceptar;
    private javax.swing.JButton botonBajar;
    private javax.swing.JButton botonCancelar;
    private javax.swing.JButton botonSubir;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JList jList1;
    private javax.swing.JScrollPane jScrollPane1;
    // End of variables declaration//GEN-END:variables
    public DefaultListModel listModel;
    private frameFormulario frameForm;
}
